package com.me.modules.sla.service.impl;

import com.me.modules.common.common.Constant;
import com.me.modules.common.page.Page;
import com.me.modules.common.page.PageHelper;
import com.me.modules.common.utils.UserUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

import com.me.modules.sla.dao.SlaAlertTempDao;
import com.me.modules.sla.entity.SlaAlertTempEntity;
import com.me.modules.sla.service.SlaAlertTempService;



@Service
public class SlaAlertTempServiceImpl implements SlaAlertTempService {
	@Autowired
	private SlaAlertTempDao slaAlertTempDao;

	@Override
	public SlaAlertTempEntity queryObject(Long id){
		return slaAlertTempDao.queryObject(id);
	}

	@Override
	public List<SlaAlertTempEntity> queryList(Map<String, Object> map){
		return slaAlertTempDao.queryList(map);
	}

    @Override
    public List<SlaAlertTempEntity> queryListByBean(SlaAlertTempEntity entity) {
        return slaAlertTempDao.queryListByBean(entity);
    }

	@Override
	public int queryTotal(Map<String, Object> map){
		return slaAlertTempDao.queryTotal(map);
	}

	@Override
	public int save(SlaAlertTempEntity slaAlertTemp){
		slaAlertTemp.setCreateDate(new Date());
		slaAlertTemp.setCreateUser(UserUtils.getCurrentUser().getLoginName());
		return slaAlertTempDao.save(slaAlertTemp);
	}

	@Override
	public int update(SlaAlertTempEntity slaAlertTemp){
		slaAlertTemp.setUpdateDate(new Date());
		slaAlertTemp.setUpdateUser(UserUtils.getCurrentUser().getLoginName());
		return slaAlertTempDao.update(slaAlertTemp);
	}

	@Override
	public int delete(Long id){
        return slaAlertTempDao.delete(id);
	}

	@Override
	public int deleteBatch(Long[] ids){
        return slaAlertTempDao.deleteBatch(ids);
	}



	@Override
	public Page<SlaAlertTempEntity> findPage(SlaAlertTempEntity slaAlertTemp, int pageNum) {
		PageHelper.startPage(pageNum, Constant.pageSize);
		slaAlertTempDao.queryList(slaAlertTemp);
		return PageHelper.endPage();
	}


	@Override
	public List<Map<String, Object>> queryMapList() {
		List<SlaAlertTempEntity> list =slaAlertTempDao.queryList(null);
		List<Map<String, Object>> policyList =new ArrayList<Map<String, Object>>();
		for (SlaAlertTempEntity slaAlertTemp:list) {
			Map<String, Object> map =new HashMap<String, Object>();
			map.put("value",slaAlertTemp.getId());
			map.put("name",slaAlertTemp.getName());
			policyList.add(map);
		}
		return  policyList;
	}
}
